package com.yunhe.portal.controller;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.portal.domain.DataNewsInfo;
import com.yunhe.portal.model.DataNewsInfoVo;
import com.yunhe.portal.model.NewsInfoQueryCondition;
import com.yunhe.portal.model.PublishStatus;
import com.yunhe.portal.service.DataNewsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.yunhe.common.model.ResultObject;

import java.util.List;

/**
 * @description 新闻表
 * @author misty
 * @date 2021-10-19
 */
@Api(value = "DataNewsInfo", description = "Model_DataNewsInfo", tags = {"新闻表维护"})
@RestController
@RequestMapping(value = "/dataNewsInfo")
public class DataNewsInfoController {

    @Autowired
    private DataNewsInfoService dataNewsInfoService;

    /**
     * 新增
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("新增新闻表")
    @PostMapping("/createDataNewsInfo")
    public ResponseEntity<ResultObject> createDataNewsInfo(@RequestBody DataNewsInfo dataNewsInfo) throws ArgumentErrorException {
        dataNewsInfoService.createDataNewsInfo(dataNewsInfo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 刪除
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("根据id删除新闻表")
    @DeleteMapping("/deleteDataNewsInfo")
    public ResponseEntity<ResultObject> deleteDataNewsInfo(@RequestParam(value = "id",required = true) int id){
        dataNewsInfoService.deleteDataNewsInfo(id);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 更新
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("更新新闻表")
    @PostMapping("/updateDataNewsInfo")
    public ResponseEntity<ResultObject> updateDataNewsInfo(@RequestBody DataNewsInfo dataNewsInfo) throws ArgumentErrorException {
        dataNewsInfoService.updateDataNewsInfo(dataNewsInfo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/10/19
     **/
    @ApiOperation("根据id查询新闻表")
    @GetMapping("/findDataNewsInfoById")
    public ResponseEntity<ResultObject<DataNewsInfo>> findDataNewsInfoById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataNewsInfoService.findDataNewsInfoById(id)),HttpStatus.OK);
    }

    @ApiOperation("web根据条件查询新闻列表")
    @PostMapping("/findDataNewsInfoByCondition")
    public ResponseEntity<ResultObject<List<DataNewsInfoVo>>>findDataNewsInfoByCondition(@RequestBody NewsInfoQueryCondition newsInfoQueryCondition){
        PageResult result = dataNewsInfoService.findDataNewsInfoByCondition(newsInfoQueryCondition);
        return new ResponseEntity(new ResultObject(result),HttpStatus.OK);
    }

    /**
     * 设置置顶
     * @date 2021/07/23
     **/
    @ApiOperation("设置置顶")
    @PostMapping("/setTop")
    public ResponseEntity<ResultObject<Void>> setTop(@RequestParam(value = "id",required = true) long id) throws ArgumentErrorException {
        dataNewsInfoService.setTop(id);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    @ApiOperation("设置发布状态")
    @PostMapping("/setPublishStatus")
    public ResponseEntity<ResultObject> setPublishStatus(@RequestBody PublishStatus publishStatus) throws ArgumentErrorException {
        dataNewsInfoService.setPublishStatus(publishStatus);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

}